<!--全部图书信息-->
<html>
<head>
    <meta charset="utf-8">
    <title>全部图书信息</title>
    <style>
        body{
            background-color: rgb(240,242,245);
        }
        .ssk{
            margin: 10px auto;
            text-align: center;
        }
    </style>
</head>
<body>

<div class="ssk">
    <form class="form-inline"  id="searchform">
        <div class="input-group">
            <input type="text" placeholder="输入图书号或图书名" class="form-control" id="searchBook" name="searchWord" class="form-control">
            <span class="input-group-btn">
                            <input type="submit" value="搜索" class="btn btn-default">
            </span>
        </div>
    </form>
</div>

<!--<c:if test="${!empty books}">-->
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                查询结果：
            </h3>
        </div>
        <div class="panel-body">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>书名</th>
                    <th>作者</th>
                    <th>出版社</th>
                    <th>ISBN</th>
                    <th>价格</th>
                    <th>状态</th>
                    <th>详情</th>
                </tr>
                </thead>
                <tbody id="table_book">
                <!--<c:forEach items="${books}" var="book">-->
                    <!--<tr>-->
                        <!--<td><c:out value="${book.name}"></c:out></td>-->
                        <!--<td><c:out value="${book.author}"></c:out></td>-->
                        <!--<td><c:out value="${book.publish}"></c:out></td>-->
                        <!--<td><c:out value="${book.isbn}"></c:out></td>-->
                        <!--<td><c:out value="${book.price}"></c:out></td>-->
                        <!--<c:if test="${book.state==1}">-->
                            <!--<td>在馆</td>-->
                        <!--</c:if>-->
                        <!--<c:if test="${book.state==0}">-->
                            <!--<td>借出</td>-->
                        <!--</c:if>-->
                        <!--<td><a href="readerbookdetail.html?bookId=<c:out value="${book.bookId}"></c:out>"><button type="button" class="btn btn-success btn-xs">详情</button></a></td>-->
                    <!--</tr>-->
                <!--</c:forEach>-->
                </tbody>
            </table>
            <div class="page_num_inf">
                <i></i> 共
                <span id="totalPage_span">12</span>页<span id="totalCount_span">132</span>本
            </div>
            <!--分页按钮-->
            <nav aria-label="Page navigation">
                <ul id="page_ul" class="pagination"></ul>
            </nav>
        </div>
    </div>
<!--</c:if>-->
</body>
<script>
    var bookId;
    function mySubmit(flag){
        return flag;
    }
    $("#searchform").submit(function () {
        searchBookFuc();
        return false;
    })
    function searchBookFuc() {
        var searchBook = $("#searchBook").val();
        if(searchBook){
            searchBook = encodeURI(searchBook);
        }
        // location.href="reader_book_query.html?searchBook="+searchBook;
        loads(bookId,1,10,searchBook);
    }

    $(function () {
        bookId = $.cookie("bookId");
        $.removeCookie("bookId");
        $.removeCookie("page");
        // var bookId = getParameter("bookId");
        // alert(bookId)
        // var searchBook = getParameter("searchBook");

        loads(null,1,10,null);
    });
    function loads(bookId, currentPage, rows,searchBook) {
        // alert(111);
        $.ajax({
            type:"post",
            dataType:"json",
            url:"book/findAllBook",
            data:{"bookId":bookId,"currentPage":currentPage,"rows":rows,"searchBook":searchBook},
            success:function (data) {
                window.scrollTo(0,0);
                $("#totalPage_span").html(data.data.totalPage);
                $("#totalCount_span").html(data.data.totalCount);
                var trs = '';
                $.each(data.data.list,function (index,ele) {
                    trs += '<tr><td>'+ele.name+'</td>\n' +
                        '                <td>'+ele.author+'</td>\n' +
                        '                <td>'+ele.publish+'</td>\n' +
                        '                <td>'+ele.isbn+'</td>\n' +
                        '                <td>'+ele.price+'</td>\n';
                    if(ele.state == 1){
                        trs += '<td><a class="jump2" name="admin_book_lend.html?bookName='+ele.name+'&page=2"><button type="button" class="btn btn-primary btn-xs">借阅</button></a></td>\n';
                    }
                    if(ele.state == 0){
                        trs += '<td><a class="jump2" name="user/returnBook?book_id='+ele.book_id+'&page=2"><button type="button" class="btn btn-primary btn-xs">归还</button></a></td>\n';
                    }
                    trs += '<td><a class="jump2" name="reader_book_detail.html?bookId='+ele.book_id+'"><button type="button" class="btn btn-success btn-xs">详情</button></a></td></tr>';
                    return;
                });
                $("#table_book").html(trs);
                $(".jump2").click(function () {
                    setCookies($(this).prop("name"));
                    $("#middle").load($(this).prop("name"));
                });
                //分页按钮
                var pagelis = '';
                pagelis +=' <li>\n' +
                    '                    <a href="javascript:loads('+bookId+','+((data.data.currentPage-1)<=1?1:(data.data.currentPage-1))+','+data.data.rows+',\''+searchBook+'\')" aria-label="Previous">\n' +
                    '                        <span aria-hidden="true">上一页</span>\n' +
                    '                    </a>\n' +
                    '                </li>';
                var begin = 1;
                var end = 10;
                if (data.data.totalPage < 10){
                    begin = 1;
                    end = data.data.totalPage;
                } else{
                    begin = data.data.currentPage -5;
                    end = data.data.currentPage + 4 ;
                    if (begin < 1){
                        begin = 1;
                        end = begin + 9;
                    }
                    if (end > data.data.totalPage) {
                        end = data.data.totalPage;
                        begin = end -9;
                    }
                }
                for (var i = begin; i <= end; i++) {

                    // pagelis += '<li><a href="#">'+i+'</a></li>';

                    if(i == data.data.currentPage){
                        pagelis += '<li class="active"><a href="javascript:loads('+bookId+','+i+','+data.data.rows+',\''+searchBook+'\')">'+i+'</a></li>';
                    }else{
                        pagelis += '<li><a href="javascript:loads('+bookId+','+i+','+data.data.rows+',\''+searchBook+'\')">'+i+'</a></li>';
                    }
                }
                pagelis += '<li>\n' +
                    '                    <a href="javascript:loads('+bookId+','+((data.data.currentPage+1)>=data.data.totalPage?data.data.totalPage:(data.data.currentPage+1))+','+data.data.rows+',\''+searchBook+'\')" aria-label="Next">\n' +
                    '                        <span aria-hidden="true">下一页</span>\n' +
                    '                    </a>\n' +
                    '                </li>';
                $("#page_ul").html(pagelis)
            }
        })
    }


</script>
</html>
